/**
* Live search, if enabled, requires /js/ajax.js
*/
function _livesearch_albums()
{
	var str = this.value;
	if (str.length<=1)
	{ 
		document.getElementById('livesearch-results').innerHTML='';
		document.getElementById('livesearch-results').style.border='0px';
		return false;
	}
	var xmlhttp = getXMLHTTPRequest();
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('livesearch-results').innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open('GET', 'albums-livesearch.php?q='+str,true);
	xmlhttp.send();
}
function handle_livesearch()
{
	document.forms['albums-livesearch'].elements['search[name]'].onkeyup = _livesearch_albums;
	document.forms['albums-livesearch'].elements['search[name]'].focus();
}

/**
* Select or deselect all visible entities
* Installs the "check/uncheck all" handler
*/
function _select_deselect_all_visible_albumss()
{
	checker = (this.checked==true);
	var lists = document.getElementsByName('albums[]');
	for(var i=0; i<lists.length; ++i)
	{
		if(lists[i].type=='checkbox')
		{
			 lists[i].checked = checker;
		}
	}
	return true;
}
function handle_select_all()
{
	if(document.getElementById('albums-checkall'))
	{
		document.getElementById('albums-checkall').onclick = _select_deselect_all_visible_albumss;
	}
}


/**
* Questions and allows to delete an item.
* Instantly installs the delete handler based on their css class selector
*/
function _confirm_deletion()
{
	var success = window.confirm('Are you sure to delete this [ albums ]?');
	return success;
}
function handle_confirm_deletion()
{
	var entries = document.getElementsByTagName('a');
	for(var i=0; i<entries.length; ++i)
	{
		if(entries[i].className=='delete')
		{
			entries[i].onclick = _confirm_deletion;
		}
	}
}

/**
* Confirms a block action before performing it
*/
function _blockactions_albums()
{
	document.forms['albums-list-form'].elements['action'].value = document.forms['albums-list-form'].elements['actions'].value;
	return window.confirm('Are you sure to perform this block action?\r\nIt may be too dangerous.');
}
function handle_block_action()
{
	if(document.forms['albums-list-form'])
	{
		document.forms['albums-list-form'].onsubmit = _blockactions_albums;
	}
}

/** Install the selected handlers */
//handle_livesearch();
handle_select_all();
handle_confirm_deletion();
handle_block_action();


/**
* Selects albums with no images
*/
/*
function _handle_select_empty_albums()
{
	checker = (this.checked==true);
	var lists = document.getElementsByName('albums[]');
	for(var i=0; i<lists.length; ++i)
	{
		if(lists[i].type=='checkbox')
		{
			 lists[i].checked = checker;
		}
	}
	return true;
}
function handle_select_empty_albums()
{
	if(document.getElementById('checkall_empty'))
	{
		document.getElementById('checkall_empty').onclick = _handle_select_empty_albums;
	}
}
handle_select_empty_albums();
*/